package cn.jorian.framework.service.impl;

import cn.jorian.framework.bean.AdjustBackBean;
import cn.jorian.framework.bean.DataBean;
import cn.jorian.framework.bean.OrderCancelBackBean;
import cn.jorian.framework.bean.ResponseResult;
import cn.jorian.framework.net.NetManager;
import cn.jorian.framework.service.IOrderCancelBackService;
import cn.jorian.framework.util.ParamUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Response;

import java.io.IOException;
import java.util.UUID;

@Service
public class OrderCancelBackServiceImpl implements IOrderCancelBackService {


    @Override
    public ResponseResult orderCancelBack() {
        OrderCancelBackBean orderCancelBackBean = new OrderCancelBackBean();
        orderCancelBackBean.setDataType(1);
        orderCancelBackBean.setOwnerCode("19940");
        orderCancelBackBean.setOrderNo("12345");
        orderCancelBackBean.setCancelTime("2024-09-24");
        orderCancelBackBean.setCancelMan("胡涛");
        orderCancelBackBean.setRemarks("取消备注");
        orderCancelBackBean.setCancelResultFlag("1");
        orderCancelBackBean.setCancelResultRemarks("取消原因");


        OrderCancelBackBean.DtlBean dtlBean = new OrderCancelBackBean.DtlBean();
        dtlBean.setOrderNo(orderCancelBackBean.getOrderNo());
        dtlBean.setOrderDtlNo("123456");
        dtlBean.setDataType(orderCancelBackBean.getDataType());
        orderCancelBackBean.addList(dtlBean);

        DataBean<OrderCancelBackBean> dataBean = new DataBean<>();
        dataBean.setInterfaceType("Cancel_Back");
        dataBean.setChannelType("cdfy-erp");
        dataBean.setInterfaceNbr(UUID.randomUUID().toString());
        dataBean.addRecord(orderCancelBackBean);

        try {
            //同步post请求
            Response<ResponseResult> response = NetManager.newInstance()
                    .getServiceApi()
                    .indocBack(ParamUtil.getParam(dataBean))
                    .execute();
            ResponseResult result = response.body();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }
    }
}
